package mytool;

import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.SimpleEmail;
 

public class Sender{
  
   
   public Sender(String mailto,String subject,String content) throws Exception   
    {    
        //SimpleEmail email = new SimpleEmail();
        HtmlEmail email = new HtmlEmail();
        email.setHostName("msa.hinet.net");
        //email.setAuthentication("PlayDoll_玩公仔@playdoll.com", "***");//邮件服务器验证：用户名/密码
        email.setCharset("UTF-8");// 必须放在前面，否则乱码
        email.addTo(mailto);
        email.setFrom("PlayDoll@yahoo.com.tw", "playdoll");
        email.setSubject(subject);
        email.setMsg(content);
        email.send();
    }
    
   /* public static void main(String aregs[]) throws Exception{
        Sender s ;//= new Sender("","","");
        
        for(int i=0 ; i<=999 ; i++)
         s=  new Sender("","","");
        //a.Sender("vn518802@google.com","Test你好","Test");
        
    }*/
}
/*public class Sender extends java.lang.Thread {
    private String content;
 
    private org.apache.log4j.Logger log;
    private String subject;
    private String to;
    private static Properties p = null;
 
    public static void loadProperties() {
        try {
            p = new Properties();
            // log.info(this.getClass().getResource("/mail.properties").getPath());
            System.out.println(Sender.class.getResource("/mail.properties"));
            java.io.BufferedReader reader = new java.io.BufferedReader(
                    new java.io.FileReader(Sender.class.getResource(
                            "/mail.properties").getFile()));
            ;
            String str = null;
            while ((str = reader.readLine()) != null) {
                String sp[] = str.split("=");
                p.put(sp[0].trim(), sp[1].trim());
                System.out.println(sp[0].trim() + "," + sp[1].trim());
            }
 
            reader.close();
        } catch (java.io.IOException e) {
 
        }
    }
 
    public Sender(String to, String subject, String content) {
        super();
        /*if (p == null)
            loadProperties();
        this.content = content;
        this.to = to;
        log = org.apache.log4j.Logger.getLogger(this.getClass());
        // this.p = p;
        this.subject = subject;
    }
 
    public void run() {
        HtmlEmail email = new HtmlEmail();
 
        try {
 
            String host = "msa.hinet.net";//p.getProperty("host");
 
            String from = "vn518802@gmail.com";//"PlayDoll_玩公仔@gmail.com";//p.getProperty("from");
            String from_name = "PlayDoll_玩公仔";//p.getProperty("fromName");
 
            String user = "aaa";//p.getProperty("user");
            String pwd = "aaa";//p.getProperty("pwd");
            String port = "168.95.4.211";//p.getProperty("port");
 
            email.setTLS(true); // 是否TLS檢驗，某些email需要TLS安全檢驗，同理有SSL檢驗
            // email.setSSL(true);
            email.setHostName(host);
            email.setAuthentication(user, pwd); // 使用者帳號及密碼
            //email.setAuthentication(user, user);
            // email.setSslSmtpPort(port);
            email.setSmtpPort(Integer.parseInt(port));
 
            email.setFrom(from, from_name);
            email.setCharset("utf-8");
 
            email.addTo(to); // 接收方
            // email.addCc("yyyyyy@gmail.com"); //副本
            // email.addBcc("zzzzzz@gmail.com"); //密件副本
            email.setSubject(subject); // 標題
 
            // email.setTextMsg("Your email client does not support HTML messages");
            email.setHtmlMsg(content); // 内容
            email.send();
 
        } catch (EmailException e) {
            e.printStackTrace();
            log.info(e);
        } catch (Exception e) {
            e.printStackTrace();
            log.info(e);
        }
        
        //執行
        //(new Sender("vn518802@gmail.com","test","test")).start();
    }
  public static void main(String args[])
    {
        (new Sender("vn518802@yahoo.com.tw","test","test")).start();
    }*/

